<?php
/*if($howmany < $total) {
	echo '<div class="cms_prevnext">';
	echo (!empty($prevlink) && is_array($prevlink)) ? '<a href="?'.implode('&amp;',$prevlink).'" title="View the previous set of '.$howmany.' records">&laquo; Previous '.$howmany.'</a>' : '';
	echo (!empty($prevlink) && is_array($prevlink) && !empty($nextlink) && is_array($nextlink)) ? ' | ' : '';
	echo (!empty($nextlink) && is_array($nextlink)) ? '<a href="?'.implode('&amp;',$nextlink).'" title="View the next set of '.$howmany.' records">Next '.$howmany.' &raquo;</a>' : '';
	echo '</div>';
}*/
$myreturn = '';
$j=1;
$pagelinks = 0;
$firsttop = 2;
$lastbot = (ceil($total/$howmany)-($firsttop+1));
$midbot = (ceil($start/$howmany)-2);
$midtop = (ceil($start/$howmany)+2);
$querystring = (isset($qs) && !is_array($qs)) ? http_build_query(json_decode($qs)) : ((!isset($qs)) ? array() : http_build_query($qs));
#print("\n<!--\nfirsttop is $firsttop\nlastbot is $lastbot\nmidbot is $midbot\nmidtop is $midtop\n-->");
$sep = '<span class="letterlink">&hellip;</span>';
if(($start-$howmany) >= 0) {
	// Create the "previous" button
	$myreturn .= '
			<a href="?start='.($start-$howmany);
	$myreturn .= '&amp;howmany='.$howmany;
	$myreturn .= (!empty($querystring)) ? '&amp;'.$querystring : '';
	$myreturn .= '" class="letterlink">&laquo;</a>';
	$pagelinks++;
}
for($i=0;$i<($total/$howmany);$i++) {
	if(($midtop < ($lastbot-1)) && ($i == $lastbot)) {
		$myreturn .= $sep;
		$pagelinks++;
	}
	if($i<=$firsttop || $i>=$lastbot || ($i>=$midbot && $i<=$midtop)) {
		$mystart = $howmany*$i;
		$myreturn .= '
		<a href="?start='.$mystart;
		$myreturn .= '&amp;howmany='.$howmany;
		$myreturn .= (!empty($querystring)) ? '&amp;'.$querystring : '';
		$myreturn .= '" class="letterlink';
		if($i*$howmany == $start) {
			$myreturn .= ' activeletter';
			//$this->headtitle .= ' | Page '.($i+1).' of '.ceil($total/$howmany);
		}
		$myreturn .= '">'.$j.'</a>';
		$pagelinks++;
	}
	if(($midbot > ($firsttop+1) && $i == $firsttop)) {
		$myreturn .= $sep;
		$pagelinks++;
	}
	$j++;
}
if(($start+$howmany) < $total) {
	// Create the "next" button
	$myreturn .= '
			<a href="?start='.($start+$howmany);
	$myreturn .= ($howmany != 10) ? '&amp;howmany='.$howmany : '';
	$myreturn .= (!empty($_GET['letter'])) ? '&amp;letter='.$_GET['letter'] : '';
	$myreturn .= (!empty($querystring)) ? '&amp;'.$querystring : '';
	$myreturn .= '" class="letterlink">&raquo;</a>';
	
	$pagelinks++;
}

/*$myreturn .= '
	<p style="text-align: center; clear: both;">Showing results '.($start+1).'-';
$myreturn .= (($start+$howmany) <= $total) ? ($start+$howmany) : $total;
$myreturn .= ' of '.$total.'</p>';*/
$myreturn .= '
</div>';
$myreturn = '
<div class="letterlinks" style="width: '.(($pagelinks*2.6)+1).'em;">'.$myreturn;
echo $myreturn;

$endrec = (($start+$howmany) <= $total) ? ($start+$howmany) : $total;
echo '<div class="totalrecords">';
echo 'Currently showing '.($start+1).' to '.($endrec).' of '.$total.' records.';
echo '</div>';
?>